module bcd_inc (
    input  [11:0] din,
    output [11:0] dout,
    output        cout
);

  wire [2:0] dig_cout;

  bcd_inc_1dig dig_inc_0 (
      .bcd_din(din[3:0]),
      .cin(1'b1),
      .dout(dout[3:0]),
      .cout(dig_cout[0])
  );

  bcd_inc_1dig dig_inc_1 (
      .bcd_din(din[7:4]),
      .cin(dig_cout[0]),
      .dout(dout[7:4]),
      .cout(dig_cout[1])
  );

  bcd_inc_1dig dig_inc_2 (
      .bcd_din(din[11:8]),
      .cin(dig_cout[1]),
      .dout(dout[11:8]),
      .cout(dig_cout[2])
  );

  assign cout = dig_cout[2];

endmodule

module bcd_inc_1dig (
    input  [3:0] bcd_din,
    input        cin,
    output [3:0] dout,
    output       cout
);

  assign dout = cout ? 4'h0 : bcd_din + {3'b0, cin};
  assign cout = cin & (bcd_din == 4'h9);

endmodule
